package com.zxm.sunshineaiary.view.myedittext;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.Editable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.widget.EditText;

import com.zxm.sunshineaiary.activity.R;
import com.zxm.sunshineaiary.activity.R.color;

public class MyEditText extends EditText {

	private final String TAG = "MyEditText";

	private final int LINE_SPACING = 60;
	public int bottom = 0;

	public MyEditText(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		getPropertyOfXml(context, attrs);
	}

	public MyEditText(Context context, AttributeSet attrs) {
		super(context, attrs);
		getPropertyOfXml(context, attrs);
	}

	public MyEditText(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	private void getPropertyOfXml(Context context, AttributeSet attrs) {
		TypedArray ta = context.obtainStyledAttributes(attrs,
				R.styleable.MyEditText);
		this.setTextSize(ta.getDimension(R.styleable.MyEditText_text_size, 20));
		this.setGravity(Gravity.BOTTOM);

	}

	@Override
	protected void onDraw(Canvas canvas) {
		int lineHeight = this.getLineHeight();
		Paint mPaint = getPaint();
		mPaint.setColor(color.gray);
		int topPadding = this.getPaddingTop();
		int leftPadding = this.getPaddingLeft();
		// setLineSpacing(50, 0);
		mPaint.setTextSkewX((float) 0.1);// 倾斜
		canvas.translate(0, 0);

		Log.v(TAG, "topPadding===" + topPadding);
		int y = 0;
		if (bottom == 0) {
			bottom = y;
		}
		// for (int i = 0; i < getLineCount(); i++) {
		// canvas.drawLine(leftPadding, y, getRight() - leftPadding, y, mPaint);
		// y += LINE_SPACING;
		// }
		super.onDraw(canvas);
	}

	@Override
	public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
		return new TestInputConnection(super.onCreateInputConnection(outAttrs),
				false);
	}

	@Override
	public Editable getText() {

		return super.getText();
	}
}
